<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\GameServer\RechargeRecordRepository;
use App\Repositories\GameServer\PlayRecordRepository;
use App\Repositories\GameServer\GoodsRepository;
use App\Repositories\GamerRepository;
use Carbon\Carbon;

class TestController extends Controller
{
    protected $Goods;
    protected $Gamer;
    protected $Play;

    public function __construct(GoodsRepository $goods, GamerRepository $gamer, PlayRecordRepository $play)
    {

        $this->Goods = $goods;
        $this->Gamer = $gamer;
        $this->Play = $play;

    }
    public function index()
    {
        return view('admin.test.index');
    }

    public function recharge(RechargeRecordRepository $recharge)
    {
        $goods = $this->Goods->getGoods(1);
        $gamer = $this->Gamer->getGamer(127865);
        $record = [
            'account_id' => $gamer->id,
            'account_name' => $gamer->nickname,
            'price' => $goods->price,
            'jeton' => $goods->gold,
            'gift_jeton' => $goods->gift_gold,
            'item_id' => $goods->id,
            'item_name' => $goods->item_name,
            'buy_time' => Carbon::now()->toDateTimeString(),
            'note' => $goods->note,
            'total_jeton' => 1
        ];
        $recharge->addRechargeRecord($record);
    }

    public function validActive()
    {
        $start = Carbon::now()->startOfDay();
        $end = Carbon::now()->endOfDay();

        $where['start'] = $start->timestamp;
        $where['end'] = $end->timestamp;
        $where['format'] = '%k';

        $gamers = $this->Play->getValidActiveGamers($where);
        dd($gamers);
    }
}
